//
//  AdaptScreen.h
//  速停
//
//  Created by xdd on 15/12/16.
//  Copyright © 2015年 xdd_xiaojuan. All rights reserved.
//

#ifndef AdaptScreen_h
#define AdaptScreen_h


#import <UIKit/UIKit.h>

#define ORANGIN_WIDTH 320
#define ORANGIN_HEIGHT 480
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size
#define XJ_INLINE static inline
#define XJ_ALERT static inline
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1]
#define THEME_COLOR RGBCOLOR(240,216,136)
XJ_INLINE void func();
XJ_ALERT  void fun();

XJ_ALERT  UIAlertController* XJAlertWithMessage(NSString* message){
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        return alertController;
}
/**< 屏幕竖值方向的比例*/
XJ_INLINE CGFloat XJVerticalMultiplier(){
    return SCREEN_SIZE.height/ORANGIN_HEIGHT;
}


/**< 屏幕水平方向的比例*/
XJ_INLINE CGFloat XJHorizontalMultiplier(){
    return SCREEN_SIZE.width/ORANGIN_WIDTH;
}

/**< 中心点的计算*/
XJ_INLINE CGPoint XJFlexibleCenter(CGPoint iphone5SCenter){
    
    CGFloat x = iphone5SCenter.x* XJHorizontalMultiplier();
    CGFloat y = iphone5SCenter.y* XJVerticalMultiplier();
    return CGPointMake(x, y);
    
}




/**< 计算大小*/
XJ_INLINE CGSize XJFlexibleSize(CGSize iphone5SSize, BOOL adjustWidth){
    
    CGFloat width = iphone5SSize.width * XJHorizontalMultiplier();
    if (adjustWidth) {
        width = iphone5SSize.width * XJVerticalMultiplier();
    }
    CGFloat height = iphone5SSize.height * XJVerticalMultiplier();
    return CGSizeMake(width, height);
}
/**< 计算中心点*/
XJ_INLINE CGRect XJFrameWithCenterAndSize (CGPoint center, CGSize size){
    
    CGRect frame;
    frame.origin.x = center.x - size.width/2;
    frame.origin.y = center.y - size.height/2;
    frame.size = size;
    return frame;
}
/**< 计算起始点*/
XJ_INLINE CGPoint XJCenterFromFrame(CGRect frame){
    CGPoint center;
    center.x = frame.origin.x + frame.size.width/2;
    center.y = frame.origin.y + frame.size.height/2;
    
    return center;
}

/**< 传一个frame,返回一个中心点和大小*/
XJ_INLINE CGRect XJFlexibleFrame(CGRect iphone4sFrame, BOOL adjustWidth){
    CGPoint center = XJCenterFromFrame(iphone4sFrame);
    CGPoint flexibleCenter = XJFlexibleCenter(center);
    CGSize flexibelSize = XJFlexibleSize(iphone4sFrame.size,adjustWidth);
    return XJFrameWithCenterAndSize(flexibleCenter, flexibelSize);
}



#endif /* AdaptScreen_h */
